// 引入SDK核心类
// var QQMapWX = require('../../utils/qqmap-wx-jssdk');
const lon = 116.479862
const lat = 39.945773
const tubiao = 'https://www.juquduo.com/static/resourse/dianwei/红标.png';
const gamebg = 'https://www.juquduo.com/static/resourse/yeshou/地图1.jpg'
var list = [] ;
// var mks=[];
var tempmks = [] ;
var obj = {"msg":list}
var all  = new Array();
var alldd  = new Array();
var app = getApp()
var winnn = getApp().globalData.winwidth
var heigg = getApp().globalData.winheight
var num=0;
var mks = new Array()

// mks.push({id: 0,//点在楼下
//       latitude: 39.959211,
//       longitude: 116.466922,
//       iconPath: tubiao,
//       label:{content:'0'},
//       width: 35,
//       height: 40,},
//       {id: 1,
//       latitude: 39.959388,
//       longitude: 116.466598,
//       iconPath: tubiao,
//       label:{content:'1'},
//       width: 35,
//       height: 40,},
//       {id: 2,
//       latitude: 39.959492,
//       longitude: 116.466429,
//       iconPath: tubiao,
//       label:{content:'2'},
//       width: 35,
//       height: 40,},
//       {id: 3,
//       latitude: 39.957888,
//       longitude: 116.46773,
//       iconPath: tubiao,
//       label:{content:'3'},
//       width: 35,
//       height: 40,},
//       {id: 4,
//       latitude: 39.959690,
//       longitude: 116.466103,
//       iconPath: tubiao,
//       label:{content:'4'},
//       width: 35,
//       height: 40,},
//       {id: 5,
//       latitude: 39.958892,
//       longitude: 116.467355,
//       iconPath: tubiao,
//       label:{content:'5'},
//       width: 35,
//       height: 40,},
//       {id: 6,
//       latitude: 39.958785,
//       longitude: 116.467136,
//       iconPath: tubiao,
//       label:{content:'6'},
//       width: 35,
//       height: 40,},
//       {id: 7,
//       latitude: 39.958696,
//       longitude: 116.467490,
//       iconPath: tubiao,
//       label:{content:'7'},
//       width: 35,
//       height: 40,})
mks.push( { //点在朝阳公园
    id: 0,
    latitude: 39.953401,
    longitude: 116.488638,
    iconPath: tubiao,
    label:{},
    // label:{'content':0,'color':'#ffffff','anchorX':'-7','anchorY':'-32'},
    width: 35,
    height: 40,
  },{ // 获取返回结果，放到mks数组中==================
    id: 1,
    latitude: 39.955812,
    longitude: 116.485799,
    iconPath: tubiao,
    label:{},
    // label:{'content':1,'color':'#ffffff','anchorX':'-7','anchorY':'-32'},
    width: 35,
    height: 40,
  },{ // 获取返回结果，放到mks数组中
    id: 2,
    latitude: 39.954143,
    longitude: 116.484137,
    iconPath: tubiao,
    label:{},
    // label:{'content':2,'color':'#ffffff','anchorX':'-7','anchorY':'-32'},
    width: 35,
    height: 40,
  },{ // 获取返回结果，放到mks数组中
    id: 3,
    latitude: 39.951258,
    longitude: 116.484944,
    iconPath: tubiao,
    label:{},
    width: 35,
    height: 40,
  },{ // 获取返回结果，放到mks数组中
    id: 4,
    latitude: 39.948962,
    longitude: 116.481507,
    iconPath: tubiao,
    label:{},
    width: 35,
    height: 40,
  },{ // 获取返回结果，放到mks数组中
    id: 5,
    latitude: 39.945813,
    longitude: 116.481690,
    iconPath: tubiao,
    label:{},
    width: 35,
    height: 40,
  },{ // 获取返回结果，放到mks数组中
    id: 6,
    latitude: 39.944019,
    longitude: 116.483510,
    iconPath: tubiao,
    label:{},
    width: 35,
    height: 40,
  },{ // 获取返回结果，放到mks数组中
    id: 7,
    latitude: 39.940340,
    longitude: 116.481255,
    iconPath: tubiao,
    label:{},
    width: 35,
    height: 40,
  });
  // mks.push( { //点在朝阳公园
  //   id: '15',
  //   latitude: 39.933400,
  //   // longitude: 116.479862,
  //   longitude: 116.459562,
  //   iconPath: gamebg,
  //   width:  winnn,//750
  //   height: heigg,//1200
  // },{ // 获取返回结果，放到mks数组中
  //     id: 0,
  //     latitude: 39.955800,
  //     longitude: 116.485811,
  //     iconPath: tubiao,
  //     // label:{'content':0,'color':'#ffffff','anchorX':'-7','anchorY':'-32'},
  //     width: 35,
  //     height: 40,
  //   },{ // 获取返回结果，放到mks数组中==================
  //     id: 1,
  //     latitude: 39.955617,
  //     longitude: 116.486081,
  //     iconPath: tubiao,
  //     // label:{'content':1,'color':'#ffffff','anchorX':'-7','anchorY':'-32'},
  //     width: 35,
  //     height: 40,
  //   },{ // 获取返回结果，放到mks数组中
  //     id: 2,
  //     latitude: 39.955389,
  //     longitude: 116.486259,
  //     iconPath: tubiao,
  //     // label:{'content':2,'color':'#ffffff','anchorX':'-7','anchorY':'-32'},
  //     width: 35,
  //     height: 40,
  //   },{ // 获取返回结果，放到mks数组中
  //     id: 3,
  //     latitude: 39.955880,
  //     longitude: 116.486367,
  //     iconPath: tubiao,
  //     width: 35,
  //     height: 40,
  //   },{ // 获取返回结果，放到mks数组中
  //     id: 4,
  //     latitude: 39.955592,
  //     longitude: 116.485473,
  //     iconPath: tubiao,
  //     width: 35,
  //     height: 40,
  //   },{ // 获取返回结果，放到mks数组中
  //     id: 5,
  //     latitude: 39.941513,
  //     longitude: 116.483797,
  //     iconPath: tubiao,
  //     width: 35,
  //     height: 40,
  //   },{ // 获取返回结果，放到mks数组中
  //     id: 6,
  //     latitude: 39.941258,
  //     longitude: 116.482613,
  //     iconPath: tubiao,
  //     width: 35,
  //     height: 40,
  //   },{ // 获取返回结果，放到mks数组中
  //     id: 7,
  //     latitude: 39.940379,
  //     longitude: 116.478686,
  //     iconPath: tubiao,
  //     width: 35,
  //     height: 40,
  //   },{ // 获取返回结果，放到mks数组中
  //     id: 8,
  //     latitude: 39.945904,
  //     longitude: 116.481416,
  //     iconPath: tubiao,
  //     width: 35,
  //     height: 40,
  //   },{ // 获取返回结果，放到mks数组中
  //     id: 9,
  //     latitude: 39.946134,
  //     longitude: 116.480051,
  //     iconPath: tubiao,
  //     width: 35,
  //     height: 40,
  //   },{ // 获取返回结果，放到mks数组中
  //     id: 10,
  //     latitude: 39.949922,
  //     longitude: 116.481908,
  //     iconPath: tubiao,
  //     width: 35,
  //     height: 40,
  //   },{ // 获取返回结果，放到mks数组中
  //     id: 11,
  //     latitude: 39.951180,
  //     longitude: 116.485336,
  //     iconPath: tubiao,
  //     width: 35,
  //     height: 40,
  //   });
// 实例化API核心类
// var qqmapsdk = new QQMapWX({
//     key: app.globalData.key // 必填
// });  
 
//在Page({})中使用下列代码
Page({
  data:{
    mks:mks,
    jindutiao:'https://www.juquduo.com/static/resourse/dianwei/进度条1.png',
    dyxinxi:[],
    liebiao:[{activityType: "2",pointId: "4",pointName: "qqq"}],
    kedian:true,
    list:list,
    winheight:app.globalData.winheight,
    winwidth:app.globalData.winwidth,
    acid:'',
    usertype:'',
    poi: {
      latitude: lat,
      longitude: lon,
    }
    // poi: {
    //   latitude: 39.958691,
    //   longitude: 116.466496,
    // }
  },
  onLoad:function(options){
    console.log('加载时，mks：')
    console.log(mks)
    var sdsdid = options.id
    var sdsdty = options.type
    if(sdsdid==''||sdsdid==undefined){
      console.log('没有活动id')
      this.setData({acid:126,usertype:1})}
      else{
        this.setData({acid:options.id,usertype:options.type})
      }
    try {
      wx.removeStorageSync('pointcont')
    } catch (e) {
      console.log('本地存储没有清除')
    }
  },
  onReady(){
    all.pop()
  },
  zhuye(){
    wx.redirectTo({
      url: '../ayeshou/yeshou',
    })
  },
  onShow(){
    var liebiao = wx.getStorageSync('pointcont') //取出内容之后删掉存储
    try {
      wx.removeStorageSync('pointcont')
    } catch (e) {
      // Do something when catch error
      console.log('本地存储没有清除')
    }
    
    // JSON.parse(liebiao)
    console.log('liebiao',liebiao)
    if(liebiao!=''){
      all.push(liebiao)//给下方列表添加一项
    }
    var _this = this;
    _this.setData({markers:mks,botthei:100+40*all.length})

    if(all.length>4){
      _this.setData({kedian:false,jindutiao:'https://www.juquduo.com/static/resourse/dianwei/进度条2.png'})
    }else{
      _this.setData({kedian:true,jindutiao:'https://www.juquduo.com/static/resourse/dianwei/进度条1.png'})
    }
    console.log('现在显示的列表:',all)
    console.log('现在显示的列表的长度:',all.length)
    _this.setData({liebiao:all})//显示下方的列表
    // _this.setData({markers:mks})
  },
  clickmap(e){
    var that = this
    var pid = e.detail.markerId
    // console.log(mks[pid])
    // mks = e.currentTarget.dataset.markers
    // 跳转参数
    var detail = mks[pid]
    console.log('被选中点的信息：')
    console.log(detail)
    //修改覆盖物的文字
      var label = new Array
      num++
      var content='0'+num
      label.push({'content':content,'color':'#ffffff','anchorX':'-7','anchorY':'-32'})
      mks[pid].label={'content':content,'color':'#ffffff','anchorX':'-7','anchorY':'-32'}

    wx.navigateTo({
      url: './dianweidetail?id='+pid+'&acid='+that.data.acid+'&lat='+detail.latitude+'&long='+detail.longitude+'&type='+that.data.usertype,
    })
    // 修改覆盖物的图片，重新加载覆盖物
    mks[pid].iconPath = 'https://www.juquduo.com/static/resourse/dianwei/顺序框1.png'
    console.log('点图标后，mks：')
    console.log(mks)
    // that.setData({markers:mks,botthei:100+40*list.length})

    // list用来调整页面参数，修改底部框的大小，显示按钮
    list.push(detail)

    that.setData({list:list})
  },
  tijiao(){
    // 跳转到分享页面，site为2，是楼下
    wx.navigateTo({
      url: '../cshare/share?acid='+this.data.acid+'&site='+2,
    })
  },
  deletpoint(e){
    console.log('点击删除')
    console.log(e)
    // 获取序号，用来删除，然后加载页面，修改底部框的大小
    var xuhao = e.currentTarget.dataset.id
    // all.remove(xuhao)
    all.splice(xuhao , 1)
    this.setData({liebiao:all,botthei:100+40*list.length})
    //参数传到服务器，删除数据
    var actype = e.currentTarget.dataset.key.activityType
    var poid = e.currentTarget.dataset.key.pointId
    var actid = this.data.acid
    wx.request({
      url: 'https://www.juquduo.com/juquduo/activity/person/delete_point',
      data:{
        activityId:actid,
        activityType:actype,
        pointId:poid
      },
      success:function(res){
        console.log('删除成功')
        console.log(res)
      },
      fail(res){
        console.log(res)
      }
    })
  }
})